﻿using System.Timers;

namespace SimpleTerminal.Common
{
    class SimpleAnimation
    {
        private readonly System.Timers.Timer AnimationTimer = new System.Timers.Timer();
        private readonly int start;
        private readonly int end;
        private readonly int step;
        private readonly int interval;
        private int current = 0;
        public SimpleAnimation(int start, int end, int step, int interval)
        {
            this.start = start;
            this.end = end;
            this.step = step;
            this.interval = interval;
            this.current = start;
            AnimationTimer.Elapsed += ElapsedHandler;
            AnimationTimer.Interval = interval;
        }

        private void ElapsedHandler(object sender, ElapsedEventArgs e)
        {
            current += step;
            if (current >= end)
            {
                current = end;
                AnimationTimer.Stop();
            }
        }

        public void Start()
        {
            AnimationTimer.Start();
        }

        public void Stop()
        {
            AnimationTimer.Stop();
        }
    }
}
